package com.jinlingxiu.app.other.adapter

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import cn.bingoogolapple.baseadapter.BGARecyclerViewAdapter
import cn.bingoogolapple.baseadapter.BGAViewHolderHelper
import com.jinlingxiu.app.R
import com.jinlingxiu.app.other.bean.ErrorBean
import com.xdja.easymvp.utils.setVerticalDivider

/**
 * @author yuanwanli
 * @des
 * @date 2020/9/12
 */
class NoPassAdapter(recyclerView: RecyclerView) :
    BGARecyclerViewAdapter<ErrorBean>(recyclerView, R.layout.item_nopass) {
    init {
        recyclerView.layoutManager = LinearLayoutManager(mContext)
        recyclerView.setVerticalDivider(mContext, 1, R.color.line_bg)
        recyclerView.adapter = this
    }

    //将当前position的item的playing转态置反,其他数据playing全部设为false
    fun restoreAllData(position: Int) {
        for ((index, bean) in mData.withIndex()) {
            if (index == position) {
                bean.playing = !bean.playing
            } else {
                bean.playing = false
            }
        }
        notifyDataSetChanged()
    }

    override fun setItemChildListener(helper: BGAViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.ivSound)
    }

    override fun fillData(helper: BGAViewHolderHelper, position: Int, model: ErrorBean) {
        helper.setText(R.id.tvErrorInfo, "${model.soundType + model.soundInitial}出现错误")
        if (model.playing) {
            helper.setImageResource(R.id.ivSound, R.drawable.stop_sound)
        } else {
            helper.setImageResource(R.id.ivSound, R.drawable.play_sound)
        }
    }
}